<template>
  <div class="goods-hot">
    <h3>{{ titleObj[type] }}</h3>
    <!-- 商品区块 -->
    <goods-item v-for="good in hotList" :good="good"  :key="good" />
  </div>
</template>
<script>
import { ref, onMounted } from 'vue'
import { findHotGoods } from '@/api/goods'
import GoodsItem from '@/views/Category/components/goods-item'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  components: {
    GoodsItem
  },
  props: {
    type: {
      type: Number,
      default: 1
    }
  },
  setup (props) {
    const titleObj = { 1: '24小时热销榜', 2: '周热销榜', 3: '总热销榜' }

    const hotList = ref([])
    const route = useRoute()
    const getHotList = async () => {
      const { result } = await findHotGoods({
        id: route.params.id,
        type: props.type
      })
      // console.log(result)
      hotList.value = result
    }

    onMounted(() => {
      getHotList()
    })

    return { titleObj, hotList }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
</style>
